﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for clsCAPLOP
/// </summary>
public class clsCAPLOP
{
	public clsCAPLOP()
	{
		//
		// TODO: Add constructor logic here
		//
    }

    #region Select
    public DataTable Select()
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        try
        {
            dt = connect.GetSelectCommand("CAPLOP_Select", null);
        }
        catch        
        {
            dt = null;
        }
        return dt;
    }
    #endregion

    #region Insert
    public string Insert(string mach, string tencaplop, float thoigianhoc, int tongtienthu, int thutu)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[5];
        para[0] = new SqlParameter("@mach", mach);        
        para[1] = new SqlParameter("@tencaplop", tencaplop);
        para[2] = new SqlParameter("@thoigianhoc", thoigianhoc);
        para[3] = new SqlParameter("@tongtienthu", tongtienthu);
        para[4] = new SqlParameter("@thutu", thutu);

        try
        {
            connect.ExecuteQuery("CAPLOP_Insert", para);
            return "OK";
        }

        catch 
        {
            return "ERR";
        }
    }
    #endregion

    #region Update
    public string Update(int sttcaplop, string mach, string tencaplop, float thoigianhoc, int tongtienthu, int thutu)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[6];
        para[0] = new SqlParameter("@sttcaplop", sttcaplop);        
        para[1] = new SqlParameter("@mach", mach);
        para[2] = new SqlParameter("@tencaplop", tencaplop);
        para[3] = new SqlParameter("@thoigianhoc", thoigianhoc);
        para[4] = new SqlParameter("@tongtienthu", tongtienthu);
        para[5] = new SqlParameter("@thutu", thutu);

        try
        {
            connect.ExecuteQuery("CAPLOP_Update", para);
            return "OK";
        }

        catch
        {
            return "ERR";
        }
    }
    #endregion

    #region Delete
    public string Delete(int sttcaplop)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@sttcaplop", sttcaplop);

        try
        {
            connect.ExecuteQuery("CAPLOP_Delete", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    #endregion

    #region GetById
    public static DataTable GetById(int F_STTCAPLOP)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_STTCAPLOP", F_STTCAPLOP);
        try
        {
            dt = connect.GetSelectCommand("CAPLOP_GetById", para);
        }
        catch
        { }
        return dt;
    }
    #endregion

    #region Get List By Lop
    public static DataTable GetListByLop(string F_MALOP)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MALOP", F_MALOP);
        try
        {
            dt = connect.GetSelectCommand("CAPLOP_GetListByLop", para);
        }
        catch
        { }
        return dt;
    }
    #endregion
    #region Get List By Lop
    public static DataTable GetAllListNotByLop()
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        //SqlParameter[] para = new SqlParameter[1];
        //para[0] = new SqlParameter("@F_MALOP", F_MALOP);
        try
        {
            dt = connect.GetSelectCommand("CAPLOP_GetAllListNotByLop", null);
        }
        catch
        { }
        return dt;
    }
    #endregion
    
    #region GetById
    public static DataTable GetByMaCHN(string F_MACHN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACHN", F_MACHN);
        try
        {
            dt = connect.GetSelectCommand("CAPLOP_Select_by_F_MACHN", para);
        }
        catch
        { }
        return dt;
    }
    #endregion
}